/**
 * 员工相关 API
 */

import type { Employee } from '../types'
import { get, post, patch, del } from './request'
import { API_ENDPOINTS } from './config'

/**
 * 获取所有员工
 */
export function getEmployees(): Promise<Employee[]> {
  return get<Employee[]>(API_ENDPOINTS.employees)
}

/**
 * 获取单个员工
 */
export function getEmployee(id: number | string): Promise<Employee> {
  return get<Employee>(API_ENDPOINTS.employee(id))
}

/**
 * 创建员工
 */
export function createEmployee(employee: Omit<Employee, 'id'>): Promise<Employee> {
  return post<Employee>(API_ENDPOINTS.employees, employee)
}

/**
 * 更新员工信息
 */
export function updateEmployee(id: number | string, updates: Partial<Employee>): Promise<Employee> {
  return patch<Employee>(API_ENDPOINTS.employee(id), updates)
}

/**
 * 删除员工
 */
export function deleteEmployee(id: number | string): Promise<void> {
  return del(API_ENDPOINTS.employee(id))
}

/**
 * 批量创建员工
 */
export async function batchCreateEmployees(employees: Omit<Employee, 'id'>[]): Promise<Employee[]> {
  const results = await Promise.all(employees.map(emp => createEmployee(emp)))
  return results
}

/**
 * 批量删除员工
 */
export async function batchDeleteEmployees(ids: (number | string)[]): Promise<void> {
  await Promise.all(ids.map(id => deleteEmployee(id)))
}
